package com.yth;

import com.yth.bean.TestSetPropertiesBean;
import com.yth.extension.TestApplicationContextInitializer;
import com.yth.util.AssertUtils;
import com.yth.util.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

/**
 * @author yutianhong
 * @version 1.0
 * @since 2023/08/29 13:53:03
 */
@Slf4j
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        new SpringApplicationBuilder(Application.class)
                .initializers(new TestApplicationContextInitializer())
                .run(args);

        long end = System.currentTimeMillis();
        log.info("Service(spring boot) startup in {} ms", (end - start));
        validate();
    }

    static void validate() {
        TestSetPropertiesBean testSetPropertiesBean = SpringUtils.getApplicationContext().getBean(TestSetPropertiesBean.class);
        AssertUtils.equals("bar", testSetPropertiesBean.bar);
        AssertUtils.equals("fox", testSetPropertiesBean.qux);
        AssertUtils.equals("modified", testSetPropertiesBean.testField);
        AssertUtils.equals("modified-originConfig", testSetPropertiesBean.testPropertiesSourceField);
    }

}
